package com.goodving.guli.database;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;

import com.goodving.guli.bt.model.BasicDateData;
import com.goodving.guli.bt.model.C1495q;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.utility.Constants;
import com.goodving.guli.view.C3657a;
import com.goodving.guli.view.C4220a;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;




/* renamed from: cn.com.smartdevices.bracelet.d.y */
class C0878y {
    private static final String f4459a = "MDB";

    private C0878y() {
    }

    public static int m9015a(SQLiteDatabase sQLiteDatabase, String str, C1495q c1495q) {
        String[] strArr = new String[]{str, C3657a.f18328f + c1495q.m12347b()};
        return sQLiteDatabase.delete(C0841E.f4320a, "date>? AND type=?", strArr);
    }

//    public static Partner m9016a(SQLiteDatabase sQLiteDatabase, String str) {
//        Partner partner = null;
//        String[] strArr = new String[]{SocialConstants.PARAM_URL, C1542f.f7839h, SocialConstants.PARAM_TITLE, C0838B.f4315f, C0838B.f4316g, C0860g.f4380d, C0838B.f4317h, C1489f.f7483n, "status"};
//        SQLiteDatabase sQLiteDatabase2 = sQLiteDatabase;
//        Cursor query = sQLiteDatabase2.query(C0837A.f4306a, strArr, "third_app_id = ?", new String[]{str}, partner, partner, partner);
//        if (query != null) {
//            try {
//                if (query.getCount() > 0) {
//                    query.moveToFirst();
//                    partner = Partner.fromCursor(query);
//                    query.close();
//                }
//            } finally {
//                query.close();
//            }
//        }
//        return partner;
//    }

    public static String m9017a(SQLiteDatabase sQLiteDatabase, String str, C1495q c1495q, int i) {
        String str2 = null;
        SQLiteDatabase sQLiteDatabase2 = sQLiteDatabase;
        Cursor query = sQLiteDatabase2.query(C0841E.f4320a, i == 1 ? new String[]{"summary_hr"} : new String[]{"summary"}, "date=? AND type=?", new String[]{str, String.valueOf(c1495q.m12347b())}, null, null, null);
        if (query != null) {
            try {
                if (query.getCount() > 0) {
                    query.moveToFirst();
                    str2 = query.getString(0);
                } else {
                    query.close();
                }
            } finally {
                query.close();
            }
        }
        return str2;
    }

    public static String m9018a(SQLiteDatabase sQLiteDatabase, String str, boolean z) throws Throwable {
        Throwable th;
        Cursor cursor = null;
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        String[] strArr;
        String[] strArr2 = new String[]{C0862i.f4387b};
        long currentTimeMillis = System.currentTimeMillis();
        String str2 = "key=?";
        if (z) {
            str2 = str2 + " AND expire_time>?";
            strArr = new String[]{str, String.valueOf(currentTimeMillis)};
        } else {
            strArr = new String[]{str};
        }
        try {
            Cursor query = sQLiteDatabase.query(C0859f.f4375e, strArr2, str2, strArr, null, null, null);
            if (query != null) {
                try {
                    if (query.getCount() != 0) {
                        if (query.moveToNext()) {
                            String string = query.getString(query.getColumnIndex(C0862i.f4387b));
                            if (query == null) {
                                return string;
                            }
                            query.close();
                            return string;
                        }
                        if (query != null) {
                            query.close();
                        }
                        return null;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    cursor = query;
                    if (cursor != null) {
                        cursor.close();
                    }
                    throw th;
                }
            }
            if (query != null) {
                query.close();
            }
            return null;
        } catch (Throwable th3) {
            th = th3;
            if (cursor != null) {
                cursor.close();
            }
            throw th;
        }
    }

//    public static ArrayList<HeartRateItem> m9019a(SQLiteDatabase sQLiteDatabase, int i) {
//        String[] strArr = new String[]{C0846J.f4341c, C0922g.f4596f, "type"};
//        String[] strArr2 = new String[]{String.valueOf(i), String.valueOf(0)};
//        SQLiteDatabase sQLiteDatabase2 = sQLiteDatabase;
//        Cursor query = sQLiteDatabase2.query(SyncServerData.f8318d, strArr, "type=? AND sync= ?", strArr2, null, null, null);
//        try {
//            ArrayList<HeartRateItem> fromCursor2Items = HeartRateItem.fromCursor2Items(query);
//            return fromCursor2Items;
//        } finally {
//            query.close();
//        }
//    }
//
//    public static ArrayList<HeartRateItem> m9020a(SQLiteDatabase sQLiteDatabase, int i, int i2) {
//        String[] strArr = new String[]{C0846J.f4341c, C0922g.f4596f};
//        String str = SyncServerData.f8318d;
//        String str2 = i2 + C3657a.f18328f;
//        Cursor query = sQLiteDatabase.query(str, strArr, null, null, null, null, "time DESC", str2);
//        try {
//            ArrayList<HeartRateItem> fromCursor2Items = HeartRateItem.fromCursor2Items(query);
//            return fromCursor2Items;
//        } finally {
//            query.close();
//        }
//    }

    public static ArrayList<BasicDateData> m9021a(SQLiteDatabase sQLiteDatabase, C1495q c1495q) {
        ArrayList<BasicDateData> arrayList = null;
        String[] strArr = new String[]{"date", "data", "summary", "indexs", "data_hr", "summary_hr", "source", "type"};
        String[] strArr2 = new String[]{C3657a.f18328f + c1495q.m12347b(), Constants.VIA_RESULT_SUCCESS};
        SQLiteDatabase sQLiteDatabase2 = sQLiteDatabase;
        Cursor query = sQLiteDatabase2.query(C0841E.f4320a, strArr, "type=? AND sync=?", strArr2, null, null, "date ASC");
        if (query != null) {
            arrayList = new ArrayList();
            try {
                arrayList.ensureCapacity(query.getCount());
                while (query.moveToNext()) {
                    BasicDateData basicDateData = new BasicDateData();
                    basicDateData.type = query.getInt(query.getColumnIndex("type"));
                    basicDateData.source = query.getInt(query.getColumnIndex("source"));
                    basicDateData.date = query.getString(query.getColumnIndex("date"));
                    basicDateData.data = query.getBlob(query.getColumnIndex("data"));
                    basicDateData.summary = query.getString(query.getColumnIndex("summary"));
                    basicDateData.indexs = query.getString(query.getColumnIndex("indexs"));
                    basicDateData.dataHR = query.getBlob(query.getColumnIndex("data_hr"));
                    basicDateData.summaryHR = query.getString(query.getColumnIndex("summary_hr"));
                    arrayList.add(basicDateData);
                }
                if (query != null) {
                    query.close();
                }
            } catch (Throwable th) {
                if (query != null) {
                    query.close();
                }
            }
        }
        return arrayList;
    }

    public static Map<String, String> m9022a(SQLiteDatabase sQLiteDatabase, String[] strArr) {
        if (strArr == null) {
            return new HashMap(0);
        }
        Cursor query = sQLiteDatabase.query(C0857d.f4360a, strArr, null, null, null, null, null);
        if (query == null) {
            return new HashMap(0);
        }
        Map<String, String> hashMap = new HashMap(strArr.length);
        try {
            for (String str : strArr) {
                if (C0857d.m8993a(str)) {
                    hashMap.put(str, query.getString(query.getColumnIndex(str)));
                }
            }
            return hashMap;
        } finally {
            query.close();
        }
    }

    public static boolean m9023a(SQLiteDatabase sQLiteDatabase, BasicDateData basicDateData, int i, C1495q c1495q) {
        return C0878y.m9029a(sQLiteDatabase, basicDateData.date, basicDateData.data, c1495q, i, basicDateData.summary, basicDateData.indexs);
    }

//    public static boolean m9024a(SQLiteDatabase sQLiteDatabase, HeartRateItem heartRateItem) {
//        Throwable th;
//        Cursor cursor;
//        int i = 0;
//        if (heartRateItem == null) {
//            return false;
//        }
//        try {
//            Cursor rawQuery = sQLiteDatabase.rawQuery("select time from heartrate where time = " + heartRateItem.time, null);
//            if (rawQuery != null) {
//                try {
//                    if (rawQuery.getCount() > 0) {
//                        GuliLog.m12370d(f4459a, "insertHeartRateItem duplicate at:" + heartRateItem.time);
//                        if (rawQuery == null) {
//                            return false;
//                        }
//                        rawQuery.close();
//                        return false;
//                    }
//                } catch (Throwable th2) {
//                    th = th2;
//                    cursor = rawQuery;
//                    if (cursor != null) {
//                        cursor.close();
//                    }
//                    throw th;
//                }
//            }
//            if (rawQuery != null) {
//                rawQuery.close();
//            }
//            if (sQLiteDatabase.insert(SyncServerData.f8318d, null, heartRateItem.toContentValues()) >= 0) {
//                i = 1;
//            }
//            return i & true;
//        } catch (Throwable th3) {
//            th = th3;
//            cursor = null;
//            if (cursor != null) {
//                cursor.close();
//            }
//            throw th;
//        }
//    }

    public static boolean m9025a(SQLiteDatabase sQLiteDatabase, String str, int i, String str2) {
        boolean z = true;
        try {
            sQLiteDatabase.beginTransaction();
            ContentValues contentValues = new ContentValues();
            contentValues.put("status", Integer.valueOf(i));
            contentValues.put("url", str2);
            if (sQLiteDatabase.update(C0837A.f4306a, contentValues, "third_app_id=?", new String[]{str}) <= 0) {
                z = false;
            }
            sQLiteDatabase.setTransactionSuccessful();
            return z;
        } finally {
            sQLiteDatabase.endTransaction();
        }
    }

    public static boolean m9026a(SQLiteDatabase sQLiteDatabase, String str, C1495q c1495q, byte[] bArr, String str2) throws Throwable {
        Cursor query;
        Throwable th;
        ContentValues contentValues = new ContentValues();
        contentValues.put("type", Integer.valueOf(c1495q.m12347b()));
        contentValues.put("source", Integer.valueOf(c1495q.m12346a()));
        contentValues.put("date", str);
        contentValues.put("sync", Integer.valueOf(1));
        contentValues.put("summary_hr", str2);
        contentValues.put("data_hr", bArr);
        String str3 = "date=? AND type=?";
        String[] strArr = new String[]{str, C3657a.f18328f + c1495q.m12347b()};
        try {
            boolean z;
            query = sQLiteDatabase.query(C0841E.f4320a, null, str3, strArr, null, null, null);
            if (query != null) {
                try {
                    if (query.getCount() > 0) {
                        z = sQLiteDatabase.update(C0841E.f4320a, contentValues, str3, strArr) > 0;
                        if (query != null) {
                            query.close();
                        }
                        return z;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    if (query != null) {
                        query.close();
                    }
                    throw th;
                }
            }
            z = sQLiteDatabase.insert(C0841E.f4320a, null, contentValues) > 0;
            if (query != null) {
                query.close();
            }
            return z;
        } catch (Throwable th3) {
            th = th3;
            query = null;
            if (query != null) {
                query.close();
            }
            throw th;
        }
    }

    public static boolean m9027a(SQLiteDatabase sQLiteDatabase, String str, String str2, C0890c c0890c) {
        boolean z = true;
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        try {
            String a = C0878y.m9018a(sQLiteDatabase, str, false);

            ContentValues contentValues = new ContentValues();
            contentValues.put(C0862i.f4387b, str2);
            contentValues.put("sync", Integer.valueOf(0));
            long currentTimeMillis = System.currentTimeMillis();
            switch (C0879z.f4460a[c0890c.ordinal()]) {
                case 1 /*1*/:
                    currentTimeMillis += C0859f.f4371a;
                    break;
                case C4220a.f20888k /*2*/:
                    currentTimeMillis += 86400000;
                    break;
                case C4220a.f20889l /*3*/:
                    currentTimeMillis += C0859f.f4373c;
                    break;
                default:
                    currentTimeMillis = -1;
                    break;
            }
            try {
                contentValues.put(C0860g.f4380d, Long.valueOf(currentTimeMillis));
                if (a != null) {
                    String[] strArr = new String[]{str};
                    if (sQLiteDatabase.update(C0859f.f4375e, contentValues, "key=?", strArr) <= 0) {
                        z = false;
                    }
                    return z;
                }
                contentValues.put(C0860g.f4378b, str);
                if (sQLiteDatabase.insert(C0859f.f4375e, null, contentValues) <= 0) {
                    z = false;
                }
                return z;
            } catch (Exception e) {
                GuliLog.tracePrintError("DB", e.getMessage());
                return false;
            }
        } catch (Throwable e) {
            //TBD
        }
        return true;
    }

    public static boolean m9028a(SQLiteDatabase sQLiteDatabase, String str, String str2, C1495q c1495q) {
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            return false;
        }
        try {
            sQLiteDatabase.execSQL("update date_data set summary = " + str + " where " + "date" + " = " + "'" + str2 + "'" + " and " + "type" + " = " + c1495q.m12347b() + " and " + "source" + " = " + c1495q.m12346a() + ";");
            return true;
        } catch (Exception e) {
            GuliLog.tracePrintError("DB", e.getMessage());
            return false;
        }
    }

    public static boolean m9029a(SQLiteDatabase sQLiteDatabase, String str, byte[] bArr, C1495q c1495q, int i, String str2, String str3) {
        try {
            return C0878y.m9030a(sQLiteDatabase, str, bArr, c1495q, i, str2, str3, null, null);
        } catch (Throwable e) {
            //TBD
        }
        return true;
    }

    public static boolean m9030a(SQLiteDatabase sQLiteDatabase, String str, byte[] bArr, C1495q c1495q, int i, String str2, String str3, byte[] bArr2, String str4) throws Throwable {
        Cursor query;
        Throwable th;
        ContentValues contentValues = new ContentValues();
        contentValues.put("type", Integer.valueOf(c1495q.m12347b()));
        contentValues.put("source", Integer.valueOf(c1495q.m12346a()));
        contentValues.put("date", str);
        contentValues.put("summary", str2);
        contentValues.put("indexs", str3);
        contentValues.put("data", bArr);
        contentValues.put("sync", Integer.valueOf(i));
        if (bArr2 != null && bArr2.length > 0) {
            contentValues.put("data_hr", bArr2);
        }
        if (!TextUtils.isEmpty(str4)) {
            contentValues.put("summary_hr", str4);
        }
        String str5 = "date=? AND type=?";
        String[] strArr = new String[]{str, C3657a.f18328f + c1495q.m12347b()};
        try {
            boolean z;
            query = sQLiteDatabase.query(C0841E.f4320a, null, str5, strArr, null, null, null);
            if (query != null) {
                try {
                    if (query.getCount() > 0) {
                        z = sQLiteDatabase.update(C0841E.f4320a, contentValues, str5, strArr) > 0;
                        if (query != null) {
                            query.close();
                        }
                        return z;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    if (query != null) {
                        query.close();
                    }
                    throw th;
                }
            }
            z = sQLiteDatabase.insert(C0841E.f4320a, null, contentValues) > 0;
            if (query != null) {
                query.close();
            }
            return z;
        } catch (Throwable th3) {
            th = th3;
            query = null;
            if (query != null) {
                query.close();
            }
            throw th;
        }
    }

    public static boolean m9031a(SQLiteDatabase sQLiteDatabase, String str, byte[] bArr, String str2, String str3, C1495q c1495q) throws Throwable {
        Throwable th;
        ContentValues contentValues = new ContentValues();
        contentValues.put("type", Integer.valueOf(c1495q.m12347b()));
        contentValues.put("source", Integer.valueOf(c1495q.m12346a()));
        contentValues.put("date", str);
        contentValues.put("summary", str2);
        contentValues.put("indexs", str3);
        contentValues.put("data", bArr);
        contentValues.put("sync", Integer.valueOf(0));
        String str4 = "date=? AND type=?";
        String[] strArr = new String[]{str, C3657a.f18328f + c1495q.m12347b()};
        Cursor query;
        try {
            boolean z;
            query = sQLiteDatabase.query(C0841E.f4320a, null, str4, strArr, null, null, null);
            if (query != null) {
                try {
                    if (query.getCount() > 0) {
                        z = sQLiteDatabase.update(C0841E.f4320a, contentValues, str4, strArr) > 0;
                        if (query != null) {
                            query.close();
                        }
                        return z;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    if (query != null) {
                        query.close();
                    }
                    throw th;
                }
            }
            z = sQLiteDatabase.insert(C0841E.f4320a, null, contentValues) > 0;
            if (query != null) {
                query.close();
            }
            return z;
        } catch (Throwable th3) {
            th = th3;
            query = null;
            if (query != null) {
                query.close();
            }
            throw th;
        }
    }

    public static boolean m9032a(SQLiteDatabase sQLiteDatabase, String str, byte[] bArr, String str2, String str3, C1495q c1495q, byte[] bArr2, String str4) throws Throwable {
        Cursor query;
        Throwable th;
        ContentValues contentValues = new ContentValues();
        contentValues.put("type", Integer.valueOf(c1495q.m12347b()));
        contentValues.put("source", Integer.valueOf(c1495q.m12346a()));
        contentValues.put("date", str);
        contentValues.put("summary", str2);
        contentValues.put("indexs", str3);
        contentValues.put("data", bArr);
        contentValues.put("sync", Integer.valueOf(0));
        if (bArr2 != null && bArr2.length > 0) {
            contentValues.put("data_hr", bArr2);
        }
        if (!TextUtils.isEmpty(str4)) {
            contentValues.put("summary_hr", str4);
        }
        String str5 = "date=? AND type=?";
        String[] strArr = new String[]{str, C3657a.f18328f + c1495q.m12347b()};
        try {
            boolean z;
            query = sQLiteDatabase.query(C0841E.f4320a, null, str5, strArr, null, null, null);
            if (query != null) {
                try {
                    if (query.getCount() > 0) {
                        z = sQLiteDatabase.update(C0841E.f4320a, contentValues, str5, strArr) > 0;
                        if (query != null) {
                            query.close();
                        }
                        return z;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    if (query != null) {
                        query.close();
                    }
                    throw th;
                }
            }
            z = sQLiteDatabase.insert(C0841E.f4320a, null, contentValues) > 0;
            if (query != null) {
                query.close();
            }
            return z;
        } catch (Throwable th3) {
            th = th3;
            query = null;
            if (query != null) {
                query.close();
            }
            throw th;
        }
    }

//    public static boolean m9033a(SQLiteDatabase sQLiteDatabase, ArrayList<HeartRateItem> arrayList, int i) {
//        String str = true;
//        if (arrayList == null || arrayList.size() < 1) {
//            return true;
//        }
//        try {
//            sQLiteDatabase.beginTransaction();
//            Iterator it = arrayList.iterator();
//            while (it.hasNext()) {
//                sQLiteDatabase.execSQL("update heartrate set sync = " + i + " where " + C0922g.f4596f + " = " + ((HeartRateItem) it.next()).time);
//            }
//            sQLiteDatabase.setTransactionSuccessful();
//            return str;
//        } catch (Exception e) {
//            str = "DB";
//            GuliLog.tracePrintError(str, e.getMessage());
//            return false;
//        } finally {
//            sQLiteDatabase.endTransaction();
//        }
//    }

    public static boolean m9034a(SQLiteDatabase sQLiteDatabase, ArrayList<BasicDateData> arrayList, int i, C1495q c1495q) {
        if (arrayList == null || arrayList.size() < 1) {
            return true;
        }
        try {
            sQLiteDatabase.beginTransaction();
            Iterator it = arrayList.iterator();
            boolean z = true;
            while (it.hasNext()) {
                BasicDateData basicDateData = (BasicDateData) it.next();
                z &= C0878y.m9029a(sQLiteDatabase, basicDateData.date, basicDateData.data, c1495q, i, basicDateData.summary, basicDateData.indexs);
            }
            sQLiteDatabase.setTransactionSuccessful();
            return z;
        } finally {
            sQLiteDatabase.endTransaction();
        }
    }

//    public static boolean m9035a(SQLiteDatabase sQLiteDatabase, List<Partner> list) {
//        if (list == null || list.isEmpty()) {
//            return false;
//        }
//        try {
//            sQLiteDatabase.beginTransaction();
//            boolean z = true;
//            for (Partner toContentValues : list) {
//                z &= sQLiteDatabase.insert(C0837A.f4306a, null, toContentValues.toContentValues()) >= 0 ? 1 : 0;
//            }
//            sQLiteDatabase.setTransactionSuccessful();
//            return z;
//        } finally {
//            sQLiteDatabase.endTransaction();
//        }
//    }

    public static boolean m9036a(SQLiteDatabase sQLiteDatabase, List<BasicDateData> list, int i, C1495q c1495q) {
        if (list == null || list.size() < 1) {
            return true;
        }
        try {
            sQLiteDatabase.beginTransaction();
            boolean z = true;
            for (BasicDateData basicDateData : list) {
                try {
                    z &= C0878y.m9030a(sQLiteDatabase, basicDateData.date, basicDateData.data, new C1495q(c1495q.m12347b(), basicDateData.source), i, basicDateData.summary, basicDateData.indexs, basicDateData.dataHR, basicDateData.summaryHR);
                } catch (Throwable e) {

                }
            }
            sQLiteDatabase.setTransactionSuccessful();
            return z;
        } catch (Exception e) {
            GuliLog.tracePrintInfo(f4459a, e.getMessage());
            return false;
        } finally {
            sQLiteDatabase.endTransaction();
        }
    }

    public static boolean m9037a(SQLiteDatabase sQLiteDatabase, String[] strArr, String[] strArr2) {
        if (strArr == null || C0857d.m8994a(strArr)) {
            throw new IllegalArgumentException();
        }
        ContentValues contentValues = new ContentValues();
        int i = 0;
        for (String put : strArr) {
            contentValues.put(put, strArr2[i]);
            i++;
        }
        return sQLiteDatabase.insert(C0857d.f4360a, null, contentValues) > 0;
    }

    public static String[] m9038a(SQLiteDatabase sQLiteDatabase) {
        String[] strArr = null;
        Cursor query = sQLiteDatabase.query(C0841E.f4320a, null, null, null, null, null, "date ASC");
        if (query != null) {
            try {
                if (query.getCount() > 0) {
                    strArr = new String[2];
                    query.moveToFirst();
                    strArr[0] = query.getString(query.getColumnIndex("date"));
                    query.moveToLast();
                    strArr[1] = query.getString(query.getColumnIndex("date"));
                }
                query.close();
            } catch (Throwable th) {
                query.close();
            }
        }
        return strArr;
    }

    public static Cursor m9039b(SQLiteDatabase sQLiteDatabase, C1495q c1495q) {
        String[] strArr = new String[]{"data_hr"};
        String[] strArr2 = new String[]{C3657a.f18328f + c1495q.m12347b()};
        return sQLiteDatabase.query(C0841E.f4320a, strArr, "date> '2015-08-09' AND type=?", strArr2, null, null, null);
    }

//    public static List<Partner> m9040b(SQLiteDatabase sQLiteDatabase) {
//        List<Partner> list = null;
//        SQLiteDatabase sQLiteDatabase2 = sQLiteDatabase;
//        Cursor query = sQLiteDatabase2.query(C0837A.f4306a, new String[]{SocialConstants.PARAM_URL, C1542f.f7839h, SocialConstants.PARAM_TITLE, C0838B.f4315f, C0838B.f4316g, C0860g.f4380d, C0838B.f4317h, C1489f.f7483n, "status"}, null, null, null, null, null);
//        if (query != null) {
//            try {
//                int count = query.getCount();
//                if (count > 0) {
//                    list = new ArrayList(count);
//                    while (query.moveToNext()) {
//                        list.add(Partner.fromCursor(query));
//                    }
//                    query.close();
//                }
//            } finally {
//                query.close();
//            }
//        }
//        return list;
//    }

    public static boolean m9041b(SQLiteDatabase sQLiteDatabase, ArrayList<BasicDateData> arrayList, int i, C1495q c1495q) {
        Boolean b = true;
        if (arrayList == null || arrayList.size() < 1) {
            return true;
        }
        try {
            sQLiteDatabase.beginTransaction();
            Iterator it = arrayList.iterator();
            while (it.hasNext()) {
                sQLiteDatabase.execSQL("update date_data set sync = " + i + " where " + "date" + " = " + "'" + ((BasicDateData) it.next()).date + "'" + " and " + "type" + " = " + c1495q.m12347b());
            }
            sQLiteDatabase.setTransactionSuccessful();
            return b;
        } catch (Exception e) {
            String str = "DB";
            GuliLog.tracePrintError(str, e.getMessage());
            return false;
        } finally {
            sQLiteDatabase.endTransaction();
        }
    }

//    public static boolean m9042b(SQLiteDatabase sQLiteDatabase, List<HeartRateItem> list) {
//        Throwable th;
//        Cursor cursor;
//        if (list == null || list.isEmpty()) {
//            return false;
//        }
//        try {
//            sQLiteDatabase.beginTransaction();
//            Cursor cursor2 = null;
//            boolean z = true;
//            for (HeartRateItem heartRateItem : list) {
//                try {
//                    cursor2 = sQLiteDatabase.rawQuery("select time from heartrate where time = " + heartRateItem.time, null);
//                    if (cursor2 == null || cursor2.getCount() <= 0) {
//                        ContentValues toContentValues = heartRateItem.toContentValues();
//                        toContentValues.put("sync", Integer.valueOf(1));
//                        z &= sQLiteDatabase.insert(SyncServerData.f8318d, null, toContentValues) >= 0 ? 1 : 0;
//                    } else {
//                        GuliLog.m12370d(f4459a, "insertHeartRateItem duplicate at:" + heartRateItem.time);
//                        if (cursor2 != null) {
//                            cursor2.close();
//                        }
//                        sQLiteDatabase.endTransaction();
//                        return false;
//                    }
//                } catch (Throwable th2) {
//                    th = th2;
//                    cursor = cursor2;
//                }
//            }
//            sQLiteDatabase.setTransactionSuccessful();
//            if (cursor2 != null) {
//                cursor2.close();
//            }
//            sQLiteDatabase.endTransaction();
//            return z;
//        } catch (Throwable th3) {
//            th = th3;
//            cursor = null;
//            if (cursor != null) {
//                cursor.close();
//            }
//            sQLiteDatabase.endTransaction();
//            throw th;
//        }
//    }

    public static byte[] m9043b(SQLiteDatabase sQLiteDatabase, String str, C1495q c1495q) {
        byte[] bArr = null;
        String[] strArr = new String[]{"data"};
        String[] strArr2 = new String[]{str, C3657a.f18328f + c1495q.m12347b()};
        SQLiteDatabase sQLiteDatabase2 = sQLiteDatabase;
        Cursor query = sQLiteDatabase2.query(C0841E.f4320a, strArr, "date=? AND type=?", strArr2, null, null, null);
        if (query != null) {
            try {
                if (query.getCount() != 0) {
                    query.moveToFirst();
                    bArr = query.getBlob(query.getColumnIndex("data"));
                } else {
                    query.close();
                }
            } finally {
                query.close();
            }
        }
        return bArr;
    }

    public static ArrayList<String> m9044c(SQLiteDatabase sQLiteDatabase, C1495q c1495q) {
        ArrayList<String> arrayList = null;
        String[] strArr = new String[]{"summary_hr"};
        String[] strArr2 = new String[]{String.valueOf(c1495q.m12347b())};
        SQLiteDatabase sQLiteDatabase2 = sQLiteDatabase;
        Cursor query = sQLiteDatabase2.query(C0841E.f4320a, strArr, "type=?", strArr2, null, null, null);
        if (query != null) {
            arrayList = new ArrayList();
            while (query.moveToNext()) {
                try {
                    arrayList.add(query.getString(0));
                } finally {
                    query.close();
                }
            }
        }
        return arrayList;
    }

    public static boolean m9045c(SQLiteDatabase sQLiteDatabase) {
        try {
            sQLiteDatabase.beginTransaction();
            boolean z = sQLiteDatabase.delete(C0837A.f4306a, null, null) >= 0;
            sQLiteDatabase.setTransactionSuccessful();
            return z;
        } finally {
            sQLiteDatabase.endTransaction();
        }
    }

    public static byte[] m9046c(SQLiteDatabase sQLiteDatabase, String str, C1495q c1495q) {
        byte[] bArr = null;
        String[] strArr = new String[]{"data_hr"};
        String[] strArr2 = new String[]{str, C3657a.f18328f + c1495q.m12347b()};
        SQLiteDatabase sQLiteDatabase2 = sQLiteDatabase;
        Cursor query = sQLiteDatabase2.query(C0841E.f4320a, strArr, "date=? AND type=?", strArr2, null, null, null);
        if (query != null) {
            try {
                if (query.getCount() != 0) {
                    query.moveToFirst();
                    bArr = query.getBlob(query.getColumnIndex("data_hr"));
                } else {
                    query.close();
                }
            } finally {
                query.close();
            }
        }
        return bArr;
    }

    public static byte[] m9047d(SQLiteDatabase sQLiteDatabase, String str, C1495q c1495q) {
        byte[] bArr = null;
        String[] strArr = new String[]{"summary"};
        String[] strArr2 = new String[]{str, C3657a.f18328f + c1495q.m12347b()};
        SQLiteDatabase sQLiteDatabase2 = sQLiteDatabase;
        Cursor query = sQLiteDatabase2.query(C0841E.f4320a, strArr, "date=? AND type=?", strArr2, null, null, null);
        if (query != null) {
            try {
                if (query.getCount() != 0) {
                    query.moveToFirst();
                    bArr = query.getBlob(query.getColumnIndex("summary"));
                } else {
                    query.close();
                }
            } finally {
                query.close();
            }
        }
        return bArr;
    }

    public static String m9048e(SQLiteDatabase sQLiteDatabase, String str, C1495q c1495q) {
        return C0878y.m9017a(sQLiteDatabase, str, c1495q, -1);
    }

    public static BasicDateData m9049f(SQLiteDatabase sQLiteDatabase, String str, C1495q c1495q) {
        BasicDateData basicDateData = null;
        String[] strArr = new String[]{"date", "data", "summary", "indexs", "data_hr", "summary_hr"};
        String[] strArr2 = new String[]{C3657a.f18328f + c1495q.m12347b(), str};
        SQLiteDatabase sQLiteDatabase2 = sQLiteDatabase;
        Cursor query = sQLiteDatabase2.query(C0841E.f4320a, strArr, "type=? AND date=?", strArr2, null, null, "date");
        if (query != null) {
            try {
                if (query.moveToFirst()) {
                    basicDateData = new BasicDateData();
                    basicDateData.date = query.getString(query.getColumnIndex("date"));
                    basicDateData.data = query.getBlob(query.getColumnIndex("data"));
                    basicDateData.summary = query.getString(query.getColumnIndex("summary"));
                    basicDateData.indexs = query.getString(query.getColumnIndex("indexs"));
                    basicDateData.dataHR = query.getBlob(query.getColumnIndex("data_hr"));
                    basicDateData.summaryHR = query.getString(query.getColumnIndex("summary_hr"));
                }
                if (query != null) {
                    query.close();
                }
            } catch (Throwable th) {
                if (query != null) {
                    query.close();
                }
            }
        }
        return basicDateData;
    }

    public static Cursor m9050g(SQLiteDatabase sQLiteDatabase, String str, C1495q c1495q) {
        String[] strArr = new String[]{"data_hr", "summary_hr"};
        String[] strArr2 = new String[]{str, C3657a.f18328f + c1495q.m12347b()};
        return sQLiteDatabase.query(C0841E.f4320a, strArr, "date=? AND type=?", strArr2, null, null, null);
    }
}
